﻿@using System.Text
@using AC.Service.DTO.User
@using wychuan2.com.Areas.admin
@using wychuan2.com.Extensions
@using wychuan2.com.Models

@{
    var allMenus = AdminUtils.GetMenus();
    var rootMenus = allMenus.Where(m => m.ParentId == 0).OrderBy(m => m.OrderBy);
    var userMenuIds = AdminUtils.GetUserPrivilege();
}
<nav class="navbar-default navbar-static-side" role="navigation">
    <div class="sidebar-collapse">
        <ul class="nav" id="side-menu">
            <li class="nav-header">
                <div class="dropdown profile-element">
                    <span>
                        <img alt="image" class="img-circle" src="~/img/profile_small.jpg" />
                    </span>
                    <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                        <span class="clear">
                            <span class="block m-t-xs">
                                <strong class="font-bold">@ApplicationUser.Current.UserName</strong>
                            </span> <span class="text-muted text-xs block">码农世界 <b class="caret"></b></span>
                        </span>
                    </a>
                    <ul class="dropdown-menu animated fadeInRight m-t-xs">
                        <li><a href="profile.html">个人信息</a></li>
                        <li><a href="contacts.html">联系方式</a></li>
                        <li><a href="mailbox.html">消息</a></li>
                        <li class="divider"></li>
                        <li><a href="/admin/account/logoff">注销</a></li>
                    </ul>
                </div>
                <div class="logo-element">
                    IN+
                </div>
            </li>
            @foreach (var rootMenu in rootMenus)
            {
                if (!userMenuIds.Contains(rootMenu.Id))
                {
                    continue;
                }
                var childs = allMenus.Where(m => m.ParentId == rootMenu.Id).OrderBy(m => m.OrderBy);
                string activeClass = "";
                MenuDTO currentMenu = childs.Where(c => c.Url.ToLower().Equals(Request.Path.ToLower())).FirstOrDefault();
                if (currentMenu != null)
                {
                    activeClass = "active";
                }
                <li class="@activeClass">
                    <a href="@rootMenu.Url"><i class="@rootMenu.Icon"></i> <span class="nav-label">@rootMenu.Name</span><span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">
                        @foreach (var child in childs)
                        {
                            if (!userMenuIds.Contains(child.Id))
                            {
                                continue;
                            }
                            <li class="@(child.Url.Equals(Request.Path.ToLower()) ? "active" : string.Empty)"><a href="@child.Url">@child.Name</a></li>
                        }
                    </ul>
                </li>
            }
        </ul>
    </div>
</nav>